﻿namespace YABE.Models
{
  using System.Data.Linq;
  using System.Data.Linq.Mapping;
  using System.Data;
  using System.Collections.Generic;
  using System.Reflection;
  using System.Linq;
  using System.Linq.Expressions;
  using System.ComponentModel;
  using System;

  public partial class YabeDataContext
  {
    public List<Post> GetPosts()
    {
      return Posts.ToList();
    }
    public List<Post> GetPosts(int year)
    {
      return Posts.Where(s => s.Created.Year == year).ToList();
    }

    public List<Post> GetPosts(int year, int month)
    {
      return Posts.Where(s => s.Created.Year == year && s.Created.Month == month).ToList();
    }

    public List<Post> GetPosts(int year, int month, int day)
    {
      return Posts.Where(s => s.Created.Year == year && s.Created.Month == month
          && s.Created.Day == day).ToList();
    }

    public Post GetPost(int year, int month, int day, string title)
    {
			return Posts.Single(s => s.Created.Year == year && s.Created.Month == month
			  && s.Created.Day == day && s.Title.Replace(' ', '-').ToLower() == title.ToLower());
		}

    public void AddPost(Post p)
    {
      this.Posts.InsertOnSubmit(p);
      this.SubmitChanges();
    }

    public List<MVCRoute> GetMVCRouter(bool isActive)
    {
        return (from b in MVCRoutes 
                where b.routeIsActive == true
                orderby b.routeOrder
                select b).ToList(); 
    }
  }
}
